use "$temp/nlsy_base_sample", clear

//parent income/wealth quintiles
drop if parent_inc == . | parent_house == . //require that parent income/wealth be observed
xtile parent_inc_quart = parent_income [fw = weight_1997], nq(4)
xtile parent_house_quart = parent_house [fw = weight_1997], nq(4)

//reshape to long
reshape long hgc_ enroll_ hideg_ wage_ weight_, i(uniqid) j(year)

******deflate stuff***********
merge m:1 year using "$data/GDP/gdp_pce_deflator", keep(match) nogen
replace deflator = deflator/100 //normalize
replace wage = wage/deflator //deflate labor income

****1997 deflator applied to parent information
su deflator if year == 1997
replace parent_income_1997 = parent_income/`r(mean)'
replace parent_house_value = parent_house_value/`r(mean)'

****student loans
forval y = 2005 / 2009{
	su deflator if year == `y'
	replace educ_loans = educ_loans / `r(mean)' if birthyr == `y' - 25	
}

****normalize a few things by 10k
ds parent_house_value parent_income_1997 educ_loans
foreach var in `r(varlist)'{
    replace `var' = `var' / 40000
}

//generate age variable in preparation for reshaping
gen age = year - birthyr
drop year sample sex race 
su wage, d
sort uniqid age

//4-year college enrollment
gen enroll_coll = 0
replace enroll_coll = 1 if enroll_ == 10
bys uniqid: egen enroll_coll_ever = max(enroll_coll)
tab enroll_coll_ever
drop deflator enroll_coll

*****reshape back to wide and begin generating moments
reshape wide wage_ hgc_ enroll_ hideg_ weight_, i(uniqid) j(age)
order uniqid birthyr ability* enroll_coll_ever parent_house* parent_inc* educ_loan* hgc* enroll* hideg* wage* weight*
save "$temp/nlsy_moment_data", replace





//end of dofile